package com.cskaoyan._06oop3._01polymorphic._01demo;

/**
 * @author Macro_Ray
 * @since 2024/3/13 16:55
 */
// 多态
public class Demo {
    public static void main(String[] args) {
        // 创建三个对象，并调用register方法
        Student student = new Student();
        student.setName("张三");
        student.setAge(23);

        Teacher teacher = new Teacher();
        teacher.setName("王建国");
        teacher.setAge(30);

        Administrator admin = new Administrator();
        admin.setName("管理员");
        admin.setAge(35);

        register(student);
        register(teacher);
        register(admin);

    }

    // 这个方法能接受 老师学生管理员
    public static void register(Person person) {
        person.show();
    }

}

class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void show() {
        System.out.println(name + "，" + age);
    }
}

class Student extends Person {
    @Override
    public void show() {
        System.out.println("学生的信息为：" + getName() + "," + getAge());
    }
}

class Teacher extends Person {
    @Override
    public void show() {
        System.out.println("老师的信息为：" + getName() + "," + getAge());
    }
}

class Administrator extends Person {
    @Override
    public void show() {
        System.out.println("管理员的信息为：" + getName() + "," + getAge());
    }
}
